package com.alibaba.algo.domain.user;

import com.alibaba.algo.cooperation.usercomponent.vo.res.user.EmployeePositionResVO;
import com.alibaba.algo.core.base.BaseDomain;
import com.alibaba.algo.dao.user.SysEmployeePositionMapper;
import com.alibaba.algo.entity.user.SysEmployeePosition;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;


/**
 * 类SysEmployeePosition.java的实现描述：员工和岗位关系Domain
 *
 * @author nieganggang 2021-03-12 16:08:17
 */
@Component
public class SysEmployeePositionDomain extends BaseDomain<SysEmployeePosition> {

    @Resource
    private SysEmployeePositionMapper sysEmployeePositionMapper;

    /**
     * 查询员工的岗位列表 有效数据
     *
     * @param employeeId 员工标识
     * @return 岗位列表
     */
    public List<EmployeePositionResVO> selectEmployeePositionListByEmployeeId(Long employeeId) {
        return sysEmployeePositionMapper.selectEmployeePositionListByEmployeeId(employeeId);
    }

    /**
     * 查询员工的岗位列表 全部数据
     *
     * @param employeeId 员工标识
     * @return 岗位列表
     */
    public List<EmployeePositionResVO> selectEmployeePositionListByEmployeeIdDefaultAll(Long employeeId,String isDeleted) {
        return sysEmployeePositionMapper.selectEmployeePositionListByEmployeeIdDefaultAll(employeeId,isDeleted);
    }

    /**
     * 根据员工id删除相关岗位信息（物理删除）
     *
     * @param employeeId
     * @return
     */
    public Integer deleteByEmployeeId(Long employeeId) {
        return sysEmployeePositionMapper.deleteByEmployeeId(employeeId);
    }

    /**
     * 根据岗位id删除相关岗位信息（物理删除）
     *
     * @param positionId
     * @return
     */
    public int deleteByPositionId(Long positionId) {
        return sysEmployeePositionMapper.deleteByPositionId(positionId);
    }

    /**
     * 判断employeeId和positionId不存在时新增
     *
     * @param employeeId
     * @param positionId
     */
    public void judgeAndInsert(Long employeeId, Long positionId) {
        SysEmployeePosition employeePosition = new SysEmployeePosition();
        employeePosition.setEmployeeId(employeeId);
        employeePosition.setPositionId(positionId);
        Integer count = this.countByPara(employeePosition);
        if (count > 0) {
            return;
        }
        LocalDateTime now = LocalDateTime.now();
        employeePosition.setGmtCreated(now);
        employeePosition.setGmtModified(now);
        insert(employeePosition);
    }

    public Integer deleteByMid(String mid) {
        return sysEmployeePositionMapper.deleteByMid(mid);
    }

    public Integer logicDeleteByMid(SysEmployeePosition sysEmployeePosition) {
        return sysEmployeePositionMapper.updateByMid(sysEmployeePosition);
    }

    public Integer countByMid(String mid){
        return sysEmployeePositionMapper.countByMid(mid);
    }

    public Integer updateByEmployeeId(SysEmployeePosition sysEmployeePosition){
        return sysEmployeePositionMapper.updateByEmployeeId(sysEmployeePosition);
    }

    public Integer updateByPositionId(SysEmployeePosition sysEmployeePosition){
        return sysEmployeePositionMapper.updateByPositionId(sysEmployeePosition);
    }

    public Integer updateByEmployeeIdLastModified(SysEmployeePosition sysEmployeePosition, LocalDateTime lastModifyTime){
        return sysEmployeePositionMapper.updateByEmployeeIdLastModified(sysEmployeePosition,lastModifyTime);
    }
}
